package work.xiaohong.jijin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import work.xiaohong.jijin.entity.Store;
import work.xiaohong.jijin.mapper.StoreMapper;
import work.xiaohong.jijin.service.IStoreService;

import java.util.List;


/**
 *  服务实现类
 * @author xiaohong
 * @since 2021-11-07 13:37:13
 */
@Service
@SuppressWarnings("all")
public class StoreServiceImpl extends ServiceImpl<StoreMapper, Store> implements IStoreService {

    @Autowired
    private StoreMapper storeMapper;


    /**
     * 查询已完成订单
     * @return
     */
    @Override
    public Page findIsOver(int page, int size) {
        // 构建查询条件
        QueryWrapper<Store> queryWrapper = new QueryWrapper<Store>();
        queryWrapper.in("status",1,4);
        // 根据修改时间降序
        queryWrapper.orderByDesc("gmt_modified");
        // 构建分页 下标从0开始
        Page pg = new Page(page, size);
        // 分页查询
        return storeMapper.selectPage(pg, queryWrapper);
    }

    /**
     * 查询进行中订单
     * @return
     */
    @Override
    public List<Store> findIsDoing() {
        // 构建查询条件
        QueryWrapper<Store> queryWrapper = new QueryWrapper<Store>();
        queryWrapper.in("status",0,3);
        // 根据修改时间降序
        queryWrapper.orderByDesc("gmt_create");
        // 查询数据
        return storeMapper.selectList(queryWrapper);
    }

    /**
     * 查询所有未满可赎天数的Jijin
     * @return
     */
    @Override
    public List<Store> findIsNotFree() {
        // 构建查询条件
        QueryWrapper<Store> queryWrapper = new QueryWrapper<Store>();
        queryWrapper.notIn("freeDay",0);
        // 查询数据
        return storeMapper.selectList(queryWrapper);
    }


}
